package com.donleo.stmg.entity.controller;


import com.donleo.stmg.common.api.CommonResult;
import com.donleo.stmg.entity.model.Code;
import com.donleo.stmg.entity.service.CodeService;
import com.donleo.stmg.entity.vo.CodeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 码表 前端控制器
 * </p>
 *
 * @author liangd
 * @since 2020-12-21
 */
@Api(tags = "码表管理")
@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private CodeService codeService;

    @ApiOperation("根据条件模糊查询")
    @PreAuthorize("hasAuthority('method:log:read')")
    @GetMapping("/findAll")
    public CommonResult findAll(CodeVo codeVo){
        List<Code> codeList = codeService.findAll(codeVo);
        long total = codeService.getCount(codeVo);
        return CommonResult.success(total,codeList);
    }

    /**
     * 根据类型查码表
     * @param type
     * @return
     */
    @ApiOperation("根据类型查询")
    @PreAuthorize("hasAuthority('method:log:read')")
    @GetMapping("/findByType")
    public CommonResult findByType(String type){
        List<Code> list = codeService.findByType(type);
        return CommonResult.success(list);
    }
}
